package com.casstime.ec.cloud.meeting.service.handler;

import com.casstime.ec.cloud.meeting.dao.entity.EntityRoom;
import com.casstime.ec.cloud.meeting.dao.entity.example.EntityRoomExample;
import com.casstime.ec.cloud.meeting.dao.mapper.EntityRoomMapper;
import com.casstime.ec.cloud.meeting.model.MeetingRoom;
import com.casstime.ec.cloud.meeting.values.MeetingRoomQuery;
import com.casstime.ec.cloud.meeting.values.MeetingRoomSaveParam;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MeetingRoomHandler {

  @Autowired
  private EntityRoomMapper entityRoomMapper;


  /**
   * 新增会议室
   * @param meetingRoomSaveParam
   * @return
   */
  public MeetingRoom saveMeetingRoom(MeetingRoomSaveParam meetingRoomSaveParam) {
      EntityRoom entityRoom = EntityRoom.builder()
          .roomName(meetingRoomSaveParam.getRoomName())
          .seat(meetingRoomSaveParam.getSeat())
          .status(meetingRoomSaveParam.getStatus()).build();
          entityRoomMapper.insertSelective(entityRoom);
      return MeetingRoom.get(entityRoom);
  }


  /**
   * 查询所有会议室列表
   * @return
   */
  public List<MeetingRoom> getMeetingRoomList() {
    List<MeetingRoom> meetingRoomList = new ArrayList<MeetingRoom>();
    EntityRoomExample entityRoomExample = new EntityRoomExample();
    entityRoomExample.createCriteria().andStatusEqualTo(0);
    List<EntityRoom> entityRoomList = entityRoomMapper.selectByExample(entityRoomExample);
    for(EntityRoom entityRoom : entityRoomList){
        MeetingRoom meetingRoom = MeetingRoom.get(entityRoom);
        meetingRoomList.add(meetingRoom);
    }
    return meetingRoomList;
  }


  /**
   * 根据id查询会议室
   * @param meetingRoomById
   * @return
   */
  public MeetingRoom getMeetingRoomById(Integer meetingRoomById) {
      EntityRoom entityRoom = entityRoomMapper.selectByPrimaryKey(meetingRoomById);
      return MeetingRoom.get(entityRoom);
  }


  /**
   * 根据名称查询会议室
   * @param meetingRoomName
   * @return
   */
  public List<MeetingRoom> getMeetingRoomByName(String meetingRoomName) {
      List<MeetingRoom> meetingRoomList = new ArrayList<MeetingRoom>();
      EntityRoomExample EntityRoomExample = new EntityRoomExample();
      EntityRoomExample.createCriteria().andRoomNameEqualTo(meetingRoomName);
      List<EntityRoom> entityRoomList = entityRoomMapper.selectByExample(EntityRoomExample);
      for(EntityRoom entityRoom : entityRoomList){
        MeetingRoom meetingRoom = MeetingRoom.get(entityRoom);
        meetingRoomList.add(meetingRoom);
      }
      return meetingRoomList;
  }



  /**
   * 根据状态查询会议室
   * @param meetingRoomNameStatus
   * @return
   */
  public List<MeetingRoom> getMeetingRoomByStatus(Integer meetingRoomNameStatus) {
    List<MeetingRoom> meetingRoomList = new ArrayList<MeetingRoom>();
    EntityRoomExample EntityRoomExample = new EntityRoomExample();
    EntityRoomExample.createCriteria().andStatusEqualTo(meetingRoomNameStatus);
    List<EntityRoom> entityRoomList = entityRoomMapper.selectByExample(EntityRoomExample);
    for(EntityRoom entityRoom : entityRoomList){
      MeetingRoom meetingRoom = MeetingRoom.get(entityRoom);
      meetingRoomList.add(meetingRoom);
    }
    return meetingRoomList;
  }


  /**
   * 查询会议室列表
   * @param meetingRoomQuery
   * @return
   */
  public List<MeetingRoom> getMeetingRoomListByQuery(MeetingRoomQuery meetingRoomQuery) {
    return null;
  }


  /**
   * 根据名字删除会议室
   * @param roomName
   * @return
   */
  public int removeMeetingRoomByName(String roomName) {
      int result = entityRoomMapper.deleteMeetingRoomByName(roomName);
      return result;
  }




}
